package com.topscore.uke.mvp.presenters;

import com.topscore.uke.entities.TeamPerformanceListEntity;
import com.topscore.uke.mvp.contractors.GetTeamSalesListContractor;
import com.topscore.uke.mvp.model.GetTeamSalesListModel;
import com.topscore.uke.network.BaseResponse;
import com.topscore.uke.network.request.GetTeamSalesRequest;

import java.util.List;

/**
 * Created by 71468 on 2017/10/20.
 */

public class GetTeamSalesListPresenter implements GetTeamSalesListContractor, GetTeamSalesListContractor.Presenter {
    private GetTeamSalesRequest mRequest;
    private View mView;
    private Model mModel;

    private String mStartDate,mEndDate;


    public GetTeamSalesListPresenter(View view,String startDate,String endDate) {
        this.mView = view;
        this.mModel = new GetTeamSalesListModel(new CallBack() {
            @Override
            public void getDataSuccess(BaseResponse<List<TeamPerformanceListEntity>> response) {
                mView.onGetListSuccess(response.getData());
            }

            @Override
            public void onError(int errorCode, String errorMessage) {
                mView.onFail(errorCode,errorMessage);
            }

            @Override
            public void onComplete() {
                mView.onLoadFinished();
            }
        });
        mRequest = new GetTeamSalesRequest();
        this.mStartDate = startDate;
        this.mEndDate = endDate;
        mRequest.setEndDay(mEndDate);
        mRequest.setStartDay(mStartDate);
        mRequest.setSortName(mRequest._SORT_BY_MONEY);
        mRequest.setSortType(mRequest._SORT_DESC);
    }

    @Override
    public void getList() {
        mModel.getSalesList(mRequest);
    }

    @Override
    public void getListByASC() {
        mRequest.setSortType(mRequest._SORT_ASC);
        mModel.getSalesList(mRequest);
    }

    @Override
    public void getListByDESC() {
        mRequest.setSortType(mRequest._SORT_DESC);
        mModel.getSalesList(mRequest);
    }

    @Override
    public void getListBySortMoney() {
        mRequest.setSortName(mRequest._SORT_BY_MONEY);
        mModel.getSalesList(mRequest);
    }

    @Override
    public void getListBySortCount() {
        mRequest.setSortName(mRequest._SORT_BY_COUNT);
        mModel.getSalesList(mRequest);
    }

    @Override
    public GetTeamSalesListPresenter setGroupInfo(String groupCode) {
        mRequest.setShareUserGroupCode(groupCode);
        return this;
    }
}
